from fastapi import FastAPI
import uvicorn

app = FastAPI()

count = 0
@app.get("/")
async def root():
    global count
    count +=1
    return {"message": f"Hello World {count}"}


@app.get("/api/data")
async def get_data():
    return {"data": [1, 2, 3, 4, 5]}


if __name__ == "__main__":
    # 使用uvicorn运行，默认支持Keep-Alive
    uvicorn.run(
        app,
        host="0.0.0.0",
        port=9988,
        # 长连接相关配置
        timeout_keep_alive=10,  # 保持连接时间（秒）
        # timeout_notify=30,  # 通知超时
    )
